package com.mdxx.xczd.utils;

import com.mdxx.xczd.app.App;
import com.mdxx.xczd.bean.Point;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by MD-02 on 2017/5/24.
 */

public class LocationTest {

    public static Point getLocations(){
        final List<Point> list = new ArrayList<>();
        while(true) {
            list.add(App.mPoint);
            if (list.size() == 5) break;
            try {
                Thread.currentThread().sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        return calAVGLocations(list);
       /* Point point = new Point();
        CallPoint task = new CallPoint();
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        Future<Point> submit = executorService.submit(task);
        try {
            point = submit.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        return point;*/
    }

    public static Point calAVGLocations(List<Point> list){
        Point point = new Point();
        double la = 0;
        double lo = 0;
        for (Point points : list) {
            la = la + points.getLatitude();
            lo = lo + points.getLongitude();
        }
        la = la / list.size();
        lo = lo / list.size();
        point.setLatitude(la);
        point.setLongitude(lo);
        return point;
    }



}
